home *** CD-ROM | disk | FTP | other *** search
/ Chip 2002 September / Chip_2002-09_cd1.bin / sharewar / slunec / app / httrack.exe / {app} / src_win / WinHTTrack / Iplog.cpp < prev    next >
C/C++ Source or Header  |  2000-09-16  |  9KB  |  378 lines

  1. // iplog.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Shell.h"
  6. #include "iplog.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. extern HICON httrack_icon;
  15. extern "C" char* fconcat(char*,char*);
  16.  
  17. // Helper
  18. extern LaunchHelp* HtsHelper;
  19.  
  20. #define LOW_MARK 127000
  21. #define HIGH_MARK 128000
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // Ciplog dialog
  25.  
  26.  
  27. Ciplog::Ciplog(CWnd* pParent /*=NULL*/)
  28.     : CDialog(Ciplog::IDD, pParent)
  29. {
  30.   timer=0;
  31.   txt="\n";
  32.   type=-1;
  33.   type_filter=0;
  34.   filter=0;
  35.     //{{AFX_DATA_INIT(Ciplog)
  36.     m_iplog = _T("");
  37.     //}}AFX_DATA_INIT
  38. }
  39.  
  40.  
  41. void Ciplog::DoDataExchange(CDataExchange* pDX)
  42. {
  43.     CDialog::DoDataExchange(pDX);
  44.     //{{AFX_DATA_MAP(Ciplog)
  45.     DDX_Control(pDX, IDC_HIDEINFO, m_ctl_hideinfo);
  46.     DDX_Control(pDX, IDC_log, m_ctl_iplog);
  47.     DDX_Text(pDX, IDC_log, m_iplog);
  48.     //}}AFX_DATA_MAP
  49. }
  50.  
  51.  
  52. BEGIN_MESSAGE_MAP(Ciplog, CDialog)
  53.     //{{AFX_MSG_MAP(Ciplog)
  54.     ON_EN_VSCROLL(IDC_log, OnScroll)
  55.     ON_WM_DESTROY()
  56.     ON_WM_SIZE()
  57.     ON_WM_HELPINFO()
  58.     ON_BN_CLICKED(IDC_changelog, Onchangelog)
  59.     ON_WM_TIMER()
  60.     ON_CBN_SELCHANGE(IDC_HIDEINFO, OnSelchangeHideinfo)
  61.     ON_EN_HSCROLL(IDC_log, OnScroll)
  62.     ON_BN_CLICKED(IDC_FIND, OnFind)
  63.     //}}AFX_MSG_MAP
  64.   ON_COMMAND(ID_HELP_FINDER,OnHelpInfo2)
  65.   ON_COMMAND(ID_HELP,OnHelpInfo2)
  66.     ON_COMMAND(ID_DEFAULT_HELP,OnHelpInfo2)
  67.   ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  68. END_MESSAGE_MAP()
  69.  
  70. /////////////////////////////////////////////////////////////////////////////
  71. // Ciplog message handlers
  72.  
  73.  
  74. // refresh
  75. void Ciplog::AffLogRefresh() {
  76.   if (wait_me) {
  77.     wait_me=0;
  78.     return;
  79.   }
  80.   if (type_log != type) {
  81.     type=type_log;
  82.     if (fp)
  83.       fclose(fp);
  84.     fp=NULL;
  85.   }
  86.   if (type_filter != filter) {
  87.     filter=type_filter;
  88.     if (fp)
  89.       fclose(fp);
  90.     fp=NULL;
  91.   }
  92.   
  93.   if (fp==NULL) {
  94.     txt="";
  95.     if (type_log) {
  96.       fp=fopen(fconcat(pathlog,"hts-log.txt"),"rb");
  97.       SetWindowText(LANG_E10);
  98.       m_ctl_iplog.SetWindowText(LANG_E10);
  99.       SetDlgItemText(IDC_changelog,LANG_E11);
  100.     }
  101.     else {
  102.       fp=fopen(fconcat(pathlog,"hts-err.txt"),"rb");
  103.       SetWindowText(LANG_E11);
  104.       m_ctl_iplog.SetWindowText(LANG_E11);
  105.       SetDlgItemText(IDC_changelog,LANG_E10);
  106.       if (!fp) {        /* pas de err : switcher (en cas de log unique) */
  107.         type_log=1;
  108.         GetDlgItem(IDC_changelog)->ModifyStyle(0,WS_DISABLED);
  109.       }
  110.     }
  111.     SetDlgItemText(IDC_log,txt);
  112.   }
  113.   
  114.   if (fp) {
  115.     char dat[HIGH_MARK+4]; dat[0]='\0';
  116.     clearerr(fp);
  117.     if (!feof(fp)) {
  118.       char* a=dat;
  119.       char* startline=dat;
  120.       int n=0;
  121.       int c;
  122.       while ( (!feof(fp)) && (n<HIGH_MARK) ) {
  123.         c = fgetc(fp);
  124.         n++;
  125.         if ((c>0) && (c!=EOF)) {
  126.           switch(c) {
  127.           case 13: break;
  128.           case 10: {
  129.             *a='\0';
  130.             if (filter & 1) {
  131.               if (strstr(startline,"Debug:")) {       // Θliminer dΘbug
  132.                 a=startline;
  133.               }
  134.             }
  135.             if (filter & 2) {
  136.               if (strstr(startline,"Info:")) {       // Θliminer info
  137.                 a=startline;
  138.               }
  139.             }
  140.             if (a!=startline) {
  141.               *a++=13; 
  142.               *a++=10;
  143.             }
  144.             startline=a;
  145.             /* couper en fin de ligne */
  146.             if (n>=LOW_MARK)
  147.               n=HIGH_MARK;
  148.                    }
  149.             break;
  150.           case 9: *a++=' '; break;
  151.           default:
  152.             *a++=c;
  153.             break;
  154.           }
  155.         }
  156.       }
  157.       *a='\0';
  158.     }
  159.     if (strlen(dat)>0) {
  160.       // avant d'Θcrire on sauvegarde la position (bah oui.. c chiant)
  161.       txt += dat;
  162.       int lh = m_ctl_iplog.GetScrollPos(SB_HORZ);
  163.       int lv = m_ctl_iplog.GetScrollPos(SB_VERT);
  164.       SetDlgItemText(IDC_log,txt);
  165.       m_ctl_iplog.SetScrollPos(SB_HORZ,lh);
  166.       m_ctl_iplog.SetScrollPos(SB_VERT,lv);
  167.     }
  168.   }
  169. }
  170.  
  171. BOOL Ciplog::DestroyWindow() 
  172. {
  173.   StopTimer();
  174.   if (fp)
  175.     fclose(fp);
  176.   fp=NULL;
  177.     return CDialog::DestroyWindow();
  178. }
  179.  
  180. void Ciplog::OnScroll() 
  181. {
  182.   wait_me=1;  // attendre pour le scrolling
  183. }
  184.  
  185. BOOL Ciplog::OnInitDialog() 
  186. {
  187.   wait_me=0;
  188.   fp=NULL;
  189.  
  190.     CDialog::OnInitDialog();    
  191.   SetIcon(httrack_icon,false);
  192.   SetIcon(httrack_icon,true);
  193.   EnableToolTips(true);     // TOOL TIPS
  194.   SetForegroundWindow();   // yop en premier plan!
  195.   //m_ctl_iplog.ModifyStyle(WS_DLGFRAME,WS_CAPTION|WS_BORDER);
  196.   ///m_ctl_iplog.ModifyStyle(WS_DLGFRAME,WS_BORDER);
  197.   ///m_ctl_iplog.ModifyStyleEx(0,WS_EX_CLIENTEDGE|WS_EX_DLGMODALFRAME);
  198.   //m_ctl_iplog.SetReadOnly(FALSE);     // en blanc
  199.  
  200.   // Patcher l'interface pour les Franτais ;-)
  201.   if (LANG_T(-1)) {    // Patcher en franτais
  202.     //SetDlgItemText(,"");
  203.     SetDlgItemText(IDC_STATIC_type,LANG(LANG_E4)); // "Type d'infos:");
  204.     SetDlgItemText(IDC_logtype,LANG(LANG_E5)); // "Erreurs");
  205.     SetDlgItemText(IDC_logtype2,LANG(LANG_E6)); // "Infos");
  206.     SetDlgItemText(IDC_FIND,LANG(LANG_E7)); // "Find");
  207.     //SetDlgItemText(IDOK,LANG(LANG_CLOSE)); // "FERMER");
  208.     SetCombo(this,IDC_HIDEINFO,LISTDEF_2);
  209.   }
  210.  
  211.   // dΘmarrer timer
  212.   StartTimer();
  213.  
  214.     return TRUE;  // return TRUE unless you set the focus to a control
  215.                   // EXCEPTION: OCX Property Pages should return FALSE
  216. }
  217.  
  218. // Resize
  219. void Ciplog::OnSize(UINT nType, int cx, int cy) 
  220. {
  221.   CDialog::OnSize(nType, cx, cy);
  222.  
  223.   HWND ip = ::GetDlgItem(this->m_hWnd,IDC_log);
  224.   if (ip) {
  225.     int w,h;
  226.     RECT rect;
  227.     ::GetWindowRect(ip,&rect);
  228.     // screen coord -> client coord
  229.     POINT a,b;
  230.     a.x=rect.left; a.y=rect.top; b.x=rect.right; b.y=rect.bottom;
  231.     ::ScreenToClient(this->m_hWnd,&a); ::ScreenToClient(this->m_hWnd,&b);
  232.     rect.left=a.x; rect.top=a.y; rect.right=b.x; rect.bottom=b.y;
  233.     w = max(cx - rect.left,320);
  234.     h = max(cy - rect.top,200);
  235.     ::SetWindowPos(ip,NULL,0,0,w,h,SWP_NOZORDER|SWP_NOMOVE|SWP_NOOWNERZORDER);
  236.   }
  237. }
  238.  
  239.  
  240. void Ciplog::OnDestroy() 
  241. {
  242.   if (fp) {
  243.     fclose(fp);    
  244.     fp=NULL;
  245.   }
  246.     CDialog::OnDestroy();    
  247. }
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254. // ------------------------------------------------------------
  255. // TOOL TIPS
  256. //
  257. // ajouter dans le .cpp:
  258. // remplacer les deux Wid1:: par le nom de la classe::
  259. // dans la message map, ajouter
  260. // ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )
  261. // dans initdialog ajouter
  262. // EnableToolTips(true);     // TOOL TIPS
  263. //
  264. // ajouter dans le .h:
  265. // char* GetTip(int id);
  266. // et en generated message map
  267. // afx_msg BOOL OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
  268. BOOL Ciplog::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
  269. {
  270.   TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
  271.   UINT nID =pNMHDR->idFrom;
  272.   if (pTTT->uFlags & TTF_IDISHWND)
  273.   {
  274.     // idFrom is actually the HWND of the tool
  275.     nID = ::GetDlgCtrlID((HWND)nID);
  276.     if(nID)
  277.     {
  278.       char* st=GetTip(nID);
  279.       if (st != "") {
  280.         pTTT->lpszText = st;
  281.         pTTT->hinst = AfxGetResourceHandle();
  282.         return(TRUE);
  283.       }
  284.     }
  285.   }
  286.   return(FALSE);
  287. }
  288. char* Ciplog::GetTip(int ID)
  289. {
  290.   switch(ID) {
  291.     case IDC_logtype:  return LANG(LANG_E1 /*"View error and warning reports"*/); break;
  292.     case IDC_logtype2: return LANG(LANG_E2 /*"View info report"*/); break;
  293.     case IDC_FIND:     return LANG(LANG_E8); break; 
  294.     //case IDOK:         return LANG(LANG_E3 /*"Close the log window"*/); break;
  295.     //case : return ""; break;
  296.   }
  297.   return "";
  298. }
  299. // TOOL TIPS
  300. // ------------------------------------------------------------
  301.  
  302.  
  303. // Appel aide
  304. BOOL Ciplog::OnHelpInfo2() {
  305.   return OnHelpInfo(NULL);
  306. }
  307.  
  308. BOOL Ciplog::OnHelpInfo(HELPINFO* dummy) 
  309. {
  310.   //return CDialog::OnHelpInfo(pHelpInfo);
  311.   HtsHelper->Help();
  312.   return true;
  313.   //AfxGetApp()->WinHelp(0,HELP_FINDER);    // Index du fichier Hlp
  314.   //return true;
  315. }
  316.  
  317. void Ciplog::Onchangelog() 
  318. {
  319.   if (type_log)
  320.     type_log=0;
  321.   else
  322.     type_log=1;  
  323. }
  324.  
  325. void Ciplog::OnTimer(UINT nIDEvent) 
  326. {
  327.   AffLogRefresh();
  328.     CDialog::OnTimer(nIDEvent);
  329. }
  330.  
  331. void Ciplog::StartTimer() {
  332.   if (!timer) {
  333.     timer=SetTimer(WM_TIMER,100,NULL);
  334.   }
  335. }
  336. void Ciplog::StopTimer() {
  337.   if (timer) {
  338.     KillTimer(timer);
  339.     timer=0;
  340.   }
  341. }
  342.  
  343. void Ciplog::OnSelchangeHideinfo() 
  344. {
  345.   int r=m_ctl_hideinfo.GetCurSel();
  346.   switch(r) {
  347.   case CB_ERR : break;  // pas de sΘlection
  348.   default:
  349.     type_filter=r;
  350.   break;
  351.   }
  352. }
  353.  
  354. void Ciplog::OnFind() 
  355. {
  356.   CWaitCursor wait;
  357.   CString find;
  358.   GetDlgItemText(IDC_FINDSTR,find);
  359.   find.MakeLower();
  360.   if (find.GetLength()) {
  361.     CString data;
  362.     GetDlgItemText(IDC_log,data);
  363.     data.MakeLower();
  364.     int pos=data.Find(find);
  365.     if (pos>=0) {
  366.       //m_ctl_iplog.SetScrollPos(SB_VERT,m_ctl_iplog.LineFromChar(pos));
  367.       m_ctl_iplog.Clear();
  368.       //m_ctl_iplog.SetSel(pos,pos+100);
  369.       m_ctl_iplog.SendMessage(EM_SETSEL,0,pos);
  370.       m_ctl_iplog.SendMessage(EM_EXSETSEL,0,(LPARAM) (CHARRANGE FAR *) pos);
  371.       m_ctl_iplog.SendMessage(EM_SCROLLCARET,0,0);
  372.       m_ctl_iplog.SendMessage(EM_SETSEL,-1,-1);
  373.  
  374.       //m_ctl_iplog.RedrawWindow();
  375.     }
  376.   }
  377. }
  378.